import { defineStore } from 'pinia'
import type { UserState } from '@/store/user/types'
import { UserInfo } from '@/service/modules/user/types'

export const useUserStore = defineStore({
  id: 'user',
  state: (): UserState => ({
    token: '',
    userInfo: {}
  }),
  persist: true,
  getters: {
    getToken(): string {
      return this.token
    },
    getUserInfo(): UserInfo | {} {
      return this.userInfo
    }
  },
  actions: {
    setToken(token: string): void {
      this.token = token
    },
    setUserInfo(userInfo: UserInfo): void {
      this.userInfo = userInfo
    }
  }
})
